﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace com.hyrentals.data
{
    public class RV
    {
        public string Id { get; set; }
        public string OwnerId { get; set; }
        public string Title { get; set; }
        public string Summary { get; set; }
        public RVTypeEnum RVType { get; set; }
        public string ModelStyle { get; set; }
        public DateTime MadeYear { get; set; }
        public RVMadeByEnum MadeBy { get; set; }
        public string Made { get; set; }
        public byte Sleeps { get; set; }
        public double Length { get; set; }
        public string Zip { get; set; }
        public int StateId { get; set; }
        public int CityId { get; set; }
        public string Address { get; set; }
        public RVAvailabilityTypeEnum AvailableType { get; set; }
        public RVAvailableDateInterval[] AvailableDateIntervals { get; set; }
        public string CoverPhotoId { get; set; }
        public bool IsAllowedHandleBooking { get; set; }
        public RVStatus Status { get; set; }
        public DateTime CreateTime { get; set; }

        // price
        public RVPricing Pricing { get; set; }

        // automotive
        public RVAutomotive Automotive { get; set; }

        // interiors
        public RVInterior Interior { get; set; }

        public string DisplayName
        {
            get
            {
                if (!string.IsNullOrEmpty(Title))
                {
                    return Title;
                }
                else if (!string.IsNullOrEmpty(ModelStyle))
                {
                    return ModelStyle;
                }
                else
                {
                    return NameMapping.RVTypeEnumNameArray[(int)RVType];
                }
            }
        }

        public bool ContainAutomotiveBasicFeature(RVAutomotiveBasicFeatureEnum basicFeature)
        {
            bool result = false;

            if (Automotive != null && Automotive.BasicFeatures != null)
            {
                result = Automotive.BasicFeatures.Contains(basicFeature);
            }

            return result;
        }

        public bool ContainOverdriveTransmission(RVOverdriveTransmissionEnum overdriveTrans)
        {
            bool result = false;

            if (Automotive != null && Automotive.OverdriveTransmission != null)
            {
                result = overdriveTrans == Automotive.OverdriveTransmission;
            }

            return result;
        }

        public bool ContainElectricalFeature(RVAutomotiveElectricalFeatureEnum electricalFeature)
        {
            bool result = false;

            if (Automotive != null && Automotive.ElectricalFeatures != null)
            {
                result = Automotive.ElectricalFeatures.Contains(electricalFeature);
            }

            return result;
        }

        public bool ContainEngineType(RVAutomotiveEngineTypeEnum engineType)
        {
            bool result = false;

            if (Automotive != null && Automotive.EngineType != null)
            {
                result = engineType == Automotive.EngineType;
            }

            return result;
        }

        public double? FuelConsumption
        {
            get
            {
                if (Automotive != null)
                {
                    return Automotive.FuelConsumption;
                }
                else
                {
                    return null;
                }
            } 
        }

        public string Chassis
        {
            get
            {
                if (Automotive != null)
                {
                    return Automotive.Chassis;
                }
                else
                {
                    return null;
                }
            }
        }

        public double? GrossWeight
        {
            get
            {
                if (Automotive != null)
                {
                    return Automotive.GrossWeight;
                }
                else
                {
                    return null;
                }
            }
        }

        public double? TongueWeight
        {
            get
            {
                if (Automotive != null)
                {
                    return Automotive.TongueWeight;
                }
                else
                {
                    return null;
                }
            }
        }

        public bool ContainKitchBathroomFeature(RVInteriorKitchBathroomFeatureEnum kitchBathroomFeature)
        {
            bool result = false;

            if (Interior != null && Interior.KitchBathroomFeatures != null)
            {
                result = Interior.KitchBathroomFeatures.Contains(kitchBathroomFeature);
            }

            return result;
        }

        public bool ContainBedFeature(RVInteriorBedFeatureEnum bedFeature)
        {
            bool result = false;

            if (Interior != null && Interior.BedFeatures != null)
            {
                result = Interior.BedFeatures.Contains(bedFeature);
            }

            return result;
        }

        #region functions to determine whether RV is ready to publish or booking

        public bool IsCalendarReady()
        {
            bool result = false;

            if(AvailableType == RVAvailabilityTypeEnum.Always)
            {
                result = true;
            }
            else if (AvailableType == RVAvailabilityTypeEnum.Sometimes)
            {
                if (AvailableDateIntervals != null && AvailableDateIntervals.Count() > 0)
                    result = true;
            }

            return result;
        }

        public bool IsPricingReady()
        {
            bool result = false;
            if (Pricing != null)
            {
                if (Pricing.RentalRateDaily != null
                    && Pricing.MilageFreeMilesDaily != null
                    && Pricing.MilagePerExtraMileDaily != null
                    && Pricing.DepositNonrefundableSecurityDownPayment != null
                    && Pricing.LateChargePerHour != null)
                {
                    result = true;
                }
            }

            return result;
        }

        public bool IsPublishReady()
        {
            return IsCalendarReady() && IsPricingReady();
        }

        public bool IsBookReady()
        {
            return IsPublishReady() && IsAllowedHandleBooking;
        }

        #endregion

        public bool HasCoverPhoto()
        {
            return CoverPhotoId != null;
        }
    }

    [DataContract]
    public class RVPricing
    {
        [DataMember(Name = "RR_D")]
        public decimal? RentalRateDaily { get; set; }
        [DataMember(Name = "RR_W")]
        public decimal? RentalRateWeekly { get; set; }
        [DataMember(Name = "RR_M")]
        public decimal? RentalRateMonthly { get; set; }
        [DataMember(Name = "MFM_D")]
        public int? MilageFreeMilesDaily { get; set; }
        [DataMember(Name = "MFM_W")]
        public int? MilageFreeMilesWeekly { get; set; }
        [DataMember(Name = "MFM_M")]
        public int? MilageFreeMilesMonthly { get; set; }
        [DataMember(Name = "MPEM_D")]
        public decimal? MilagePerExtraMileDaily { get; set; }
        [DataMember(Name = "MPEM_W")]
        public decimal? MilagePerExtraMileWeekly { get; set; }
        [DataMember(Name = "MPEM_M")]
        public decimal? MilagePerExtraMileMonthly { get; set; }
        [DataMember(Name = "D_NR_SDP")]
        public decimal? DepositNonrefundableSecurityDownPayment { get; set; }
        [DataMember(Name = "D_R_DP")]
        public decimal? DepositRefundableDamageProtection { get; set; }
        [DataMember(Name = "D_R_CC")]
        public decimal? DepositRefundableCleaningCharge { get; set; }
        [DataMember(Name = "LC_H")]
        public decimal? LateChargePerHour { get; set; }
        [DataMember(Name = "O_C")]
        public RVItermizedCharge[] OtherCharges { get; set; }
    }

    public class RVAvailableDateInterval
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
    }

    public class RVItermizedCharge
    {
        public string Name { get; set; }
        public decimal Charge { get; set; }
        public FrequenceEnum Frequence { get; set; }
    }

    public class RVAutomotive
    {
        public RVAutomotiveBasicFeatureEnum[] BasicFeatures { get; set; }
        public RVOverdriveTransmissionEnum? OverdriveTransmission { get; set; }
        public RVAutomotiveElectricalFeatureEnum[] ElectricalFeatures { get; set; }
        public RVAutomotiveEngineTypeEnum? EngineType { get; set; }
        public double? FuelConsumption { get; set; }
        public string Chassis { get; set; }
        public double? GrossWeight { get; set; }
        public double? TongueWeight { get; set; }
    }


    public class RVInterior
    {
        public double? SpaceWidth { get; set; }
        public double? SpaceLenght { get; set; }
        public double? BlackWaterTank { get; set; }
        public double? GreyWaterTank { get; set; }
        public double? FreshWaterTank { get; set; }
        public double? WaterHeater { get; set; }
        public double? PropaneTanks { get; set; }
        public RVInteriorKitchBathroomFeatureEnum[] KitchBathroomFeatures { get; set; }
        public RVInteriorBedFeatureEnum[] BedFeatures { get; set; }
    }

    public class Photo
    {
        public string Id { get; set; }
        public string RVId { get; set; }
        public string Description { get; set; }
        public DateTime CreatTime { get; set; }
    }

    #region enums

    public enum RVStatus : byte
    {

        NoReady = 0,
        Ready = 1,
    }

    public enum RVTypeEnum : byte
    {
        Class_A_Bus = 1,
        Class_C_Cabover = 2,
        Class_C_Slide_out_Cabover = 3,
        Temporary_Housing = 4,
        Towables = 5, 
        Other = 0,
    }

    public enum RVMadeByEnum : byte
    {
        Coachmen = 1,
        Crossroads = 2,
        Duchmen = 3,
        Fleetwood = 4,
        ForestRiver = 5,
        Heartland = 6,
        Jayco = 7,
        Keystone = 8,
        Palomino = 9,
        ThorMotor = 10,
        Winnebago = 11,
        Other = 0,
    }

    public enum RVAvailabilityTypeEnum : byte
    {
        Always = 0,
        Sometimes = 1,
    }

    public enum FrequenceEnum : byte
    {
        OneTime = 0,
        Daily = 1,
        Weekly = 2,
        Monthly = 3,
    }

    public enum RVAutomotiveBasicFeatureEnum : byte
    {
         Cruise_Control = 0,
         Factory_Cab_Air_Conditioning = 1,
         Automatic_Transmission = 2,
         Factory_Roof_Ducted_Air_Conditioning = 3,
         Power_Steering_And_Brakes = 4,
         Large_Exterior_Storage_Bay = 5,
         Dual_And_Heater = 6,
         Slide_Out = 7,
    }

    public enum RVOverdriveTransmissionEnum : byte
    {
        _6spd = 0,
        _5spd = 1,
        _4spd = 2,
    }

    public enum RVAutomotiveElectricalFeatureEnum : byte
    {
        TwelveV_Interior_Lighting = 0,
        Auxiliary_Battery = 1,
        DVD_or_VCR_Player = 2,
        AM_orFM_Radio_with_CD = 3,
        CD_Player = 4,
        TV = 5,
        Surround_Sound = 6,
        Generator = 7,
    }

    public enum RVAutomotiveEngineTypeEnum : byte
    {
        Gasoline = 0,
        Diesel = 1,
    }

    public enum RVInteriorKitchBathroomFeatureEnum : byte
    {
        Heater_and_Thermostat = 0,
        Microwave = 1,
        Regrigerator = 2,
        Water_Heater = 3,
        Range_Stove = 4,
        Oven = 5,
        Kitchen_Sink = 6,
        Wash_Basin = 7,
        Shower = 8,
        Bathtub = 9,
        Toilet = 10,
    }

    public enum RVInteriorBedFeatureEnum : byte
    {
        Double_Bed = 0,
        Couch = 1,
        Cab_over = 2,
        Dinette = 3,
        Permanent_King = 4,
        Permanent_Queen = 5,
        Permanent_Full = 6,
        Permanent_Twin = 7,
        Bunk_Beds = 8,
    }

    #endregion
}
